﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UserBackGround_CheckInfo : System.Web.UI.Page
{
    Operation operation = new Operation(); //业务类对象
    static int userid;　　　　　 //供求信息类型
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["userid"] != null)
        {
            String uid = Session["userid"].ToString();
            userid = Convert.ToInt32(uid);
        }
        if (!IsPostBack)
        {
            this.GridView1.Attributes.Add("SortExpression", "date");
            this.GridView1.Attributes.Add("SortDirection", "DESC");
            if (Session["userid"] == null)
                Response.Write("<script language=javascript>alert('会话失效，请重新登录！');</script>");
            else
            {
                GridViewBind(userid);
            }
        }
    }
    /// <summary>
    /// 绑定供求信息到GridViev控件
    /// </summary>
    /// <param name="type">供求信息类别</param>
    private void GridViewBind(int uid)
    {
        GridView1.DataSource = operation.SelectPublicInfo(uid,true);
        GridView1.DataKeyNames=new string[] {"id"};
        GridView1.DataBind();
        //显示当前页数
        lblPageSum.Text = "当前页为　" + (GridView1.PageIndex + 1) + " / " + GridView1.PageCount + "　页";
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //高亮显示指定行
            e.Row.Attributes.Add("onMouseOver", "Color=this.style.backgroundColor;this.style.backgroundColor='#FFF000'");
            e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=Color;");
            //设置审核状态，并且设置相应的颜色。
            /*if (e.Row.Cells[5].Text == "False")
            {
                e.Row.Cells[5].Text =StringFormat.HighLight("未审核",true);
            }
            else
            {
                e.Row.Cells[5].Text = StringFormat.HighLight("已审核", false);
            }*/
            e.Row.Cells[5].Text = StringFormat.HighLight("已审核", false);
            //多余字　使用...显示
            e.Row.Cells[2].Text = StringFormat.Out(e.Row.Cells[2].Text, 18);
            //删除指定行数据时，弹出询问对话框
            ((LinkButton)(e.Row.Cells[7].Controls[0])).Attributes.Add("onclick", "return confirm('是否删除当前行数据！')");
        }
    }
    
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        operation.DeleteInfo(GridView1.DataKeys[e.RowIndex].Value.ToString());
        GridViewBind(userid);
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        //分页设置
        GridView1.PageIndex = e.NewPageIndex;
        
        GridView1.DataSource = operation.SelectPublicInfo(userid, true);
        //显示当前页数
        lblPageSum.Text = "当前页为　" + (GridView1.PageIndex + 1) + " / " + GridView1.PageCount + "　页";
    }
    protected void sorted(object sender, GridViewSortEventArgs e)
    {
        //if (isSorting) return;
        // isSorting = true;

        // 从事件参数获取排序数据列
        string sortExpression = e.SortExpression.ToString();
        // 假定为排序方向为“顺序”
        //SortDirection sortDirection = SortDirection.Ascending;
        // “ASC”与事件参数获取到的排序方向进行比较，进行GridView排序方向参数的修改
        string sortDirection = "ASC";
        if (this.GridView1.Attributes["SortExpression"].CompareTo(sortExpression) == 0)
        {
            //获得下一次的排序状态
            if (this.GridView1.Attributes["SortDirection"].CompareTo(sortDirection) == 0)
            {
                sortDirection = "DESC";
            }
        }
        // 重新设定GridView排序数据列及排序方向
        this.GridView1.Attributes["SortExpression"] = sortExpression;
        this.GridView1.Attributes["SortDirection"] = sortDirection;
        // 根据GridView排序数据列及排序方向设置显示的默认数据视图
        //WebMessageBox.Show("" + sortExpression);
        if (!string.IsNullOrEmpty(sortExpression))
        {
            GridViewBind(userid);
            DataTable dt = ((DataSet)GridView1.DataSource).Tables[0];

            DataView dv = new DataView(dt);
            dv.Sort = string.Format("{0} {1}", sortExpression, sortDirection);

            GridView1.DataSource = dv;
            GridView1.DataBind();
        }
    }
}
